package org.csu.demo.util;

import java.util.Map;

public class ThreadLocalUtil {

    private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();


    //获取值
    public static <T> T get() {
        return (T) THREAD_LOCAL.get();
    }

    //获取请求头中的用户名
    public static String getUsername(){
        Map<String, Object> map = ThreadLocalUtil.get();
        String username = (String) map.get("username");
        return username;
    }


    //存储键值对
    public static void set(Object value){THREAD_LOCAL.set(value);}

    //清除ThreadLocal 防止内存泄露
    public static void remove(){THREAD_LOCAL.remove();}
}
